﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;

namespace QuanLyThuNgan
{
    public partial class rpt_InHetCa : DevExpress.XtraReports.UI.XtraReport
    {
        public rpt_InHetCa()
        {
            InitializeComponent();
        }
        public int iTong = 0, iHoanTien=0, iTongTienNop=0;
        CaThuNganCTL caThuNganCtl = new CaThuNganCTL();
        CaThuNganDTO caThuNganDto = new CaThuNganDTO();
        int iIDCaThuNgan = 0;
        private void rpt_InHetCa_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            string sNgay = Uit.it_Date.CurrentDate();
            string sGioIn = Uit.it_Date.CurrentTime();
            DataSet ds = new DataSet();
            //gio in-------------------
            string[] gio= sGioIn.Split(':',' ');
            string sgio= gio[0]+":"+gio[1];
            xrLGioIn.Text = sgio;
            //ngay in-----------------------------
            string[] parama = sNgay.Split('/', ' ');
            string sNgayThangNam = "Ngày " + parama[0] + "Tháng " + parama[1] + " Năm " + parama[2];
            xrLNgayLap.Text = sNgayThangNam;
            //in thong het ca---------------------------
            int iIDNguoiDung= frmLogin.nd.IDNguoiDung;
            DataTable dt = caThuNganCtl.m_SelectInHetCa(iIDNguoiDung);
            foreach (DataRow dr in dt.Rows)
            {
                xrLThuNgan.Text = dr["NguoiThu"].ToString();
                xrLNgay.Text = dr["NgayDangKy"].ToString();
                xrLCa.Text = dr["TenCaLamViec"].ToString();
                xrLNoiThu.Text = dr["TenDonVi"].ToString();
                //xrLNguoiNopTien.Text = dr["NguoiThu"].ToString();
                xrLNguoiLap.Text = dr["NguoiThu"].ToString();
                iIDCaThuNgan = Uit.it_Parse.ToInteger(dr["IDCaThuNgan"].ToString());
            }

            DataTable dttong = caThuNganCtl.m_SelectChiTietNopTien(iIDCaThuNgan);
            foreach (DataRow dr in dttong.Rows)
            {
                if (dr["Loai"].ToString() == "1")
                {
                    iTong = iTong + Uit.it_Parse.ToInteger(dr["DaXacNhan"].ToString());
                }
                else
                {
                    if (dr["Loai"].ToString() == "2")
                    {
                        iHoanTien = Uit.it_Parse.ToInteger(dr["DaXacNhan"].ToString());
                    }
                }
                
            }
            iTongTienNop = iTong - iHoanTien;
            if (iTongTienNop >= 0)
            {
                xrLTongTienNop.Text = "Tổng số tiền phải nộp";
                xrLTongTienNopHoan.Text = Uit.it_Parse.ToString(iTongTienNop);
            }
            else
            {
                xrLTongTienNop.Text = "Tiền hoàn lại ";
                xrLTongTienNopHoan.Text = Uit.it_Parse.ToString(iTongTienNop);
            }
            
            xrLTong.Text = Uit.it_Parse.ToString(iTong);
            xrLHoanTien.Text = Uit.it_Parse.ToString(iHoanTien);

            this.DataSource = Frm_XacNhanHetCa.ds;
        }

    }
}
